package org.surfnet.oaaas.selenium;

import java.io.IOException;

import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.entity.StringEntity;
import org.apache.http.localserver.LocalTestServer;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler; 

public class TestSample {
	public static void main(String[] args) {
		try {
			LocalTestServer clientServer = new LocalTestServer(null, null);
			clientServer.start();

			String testBaseUri = String.format("http://%s:%d", clientServer
					.getServiceAddress().getHostName(), clientServer
					.getServiceAddress().getPort());
			System.out.println(testBaseUri);

			TestRequestHandler requestHandler = new TestRequestHandler();
			String accessTokenRedirectUri = testBaseUri + "/hello";
			
			
			clientServer.register("/hello", requestHandler);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	private static class TestRequestHandler implements HttpRequestHandler {
		public TestRequestHandler() {

		}

		@Override
		public void handle(HttpRequest req, HttpResponse rep, HttpContext arg2)
				throws HttpException, IOException {
			// TODO Auto-generated method stub
			System.out.println("hello world@"); 
			
			rep.setEntity(new StringEntity("dummy response"));
		}

	}
}
